import java.util.Stack;

class MinStack {

    Stack<Integer> stack1;

    Stack<Integer> minstack;

    public MinStack() {

        stack1 = new Stack<>();

        minstack = new Stack<>();

        minstack.push(Integer.MAX_VALUE);

    }


    public void push(int val) {

        stack1.push(val);

        if (minstack.peek() >= val) {

            minstack.push(val);

        }


    }


    public void pop() {

        if (stack1.peek().equals(minstack.peek())) {

            stack1.pop();

            minstack.pop();

        } else stack1.pop();


    }


    public int getMin() {

        return minstack.peek();


    }


    public int top() {

        return stack1.peek();

    }
}